package com.awakening.o2o.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:这个程序员有纹身
 * @Date: Created in 16:18 2018\1\6 0006
 */
@Configuration
public class PathUtil {
    private static String separator = System.getProperty("file.separator");

    private static String winPath;

    private static String linuxPath;

    private static String shopRelevantPath;

    @Value("${win.base.path}")
    public void setWinPath(String winPath) {
        PathUtil.winPath = winPath;
    }

    @Value("${linux.base.path}")
    public void setLinuxPath(String linuxPath) {
        PathUtil.linuxPath = linuxPath;
    }

    @Value("${shop.relevant.path}")
    public void setShopRelevantPath(String shopRelevantPath) {
        PathUtil.shopRelevantPath = shopRelevantPath;
    }

    public static String getImgBasePath(){
        String os = System.getProperty("os.name");
        String basePath = "";
        //根据存储系统的类别，指定根路径
        if(os.toLowerCase().startsWith("win")){
            basePath=winPath;
        }else{
            basePath=linuxPath;
        }
        basePath = basePath.replace("/",separator);
        return basePath;
    }

    public static String getShopImagePath(long shopId){
        String imagePath = shopRelevantPath + shopId +separator;
        return imagePath.replace("/",separator);
    }
}
